#!/usr/bin/env python
#--------------------------------------------------------------
# Author: Herbert Oliveira
# Parse CSV to HTML
#
#--------------------------------------------------------------

import csv
import sys

if len(sys.argv) < 1:
  print "Usage: ./csv-html.py <your CSV file>"
  print
  print
  exit(0)

# Open the CSV file for reading
reader = csv.reader(open(sys.argv[1], "rb"), delimiter=';', quoting=csv.QUOTE_NONE)

# Create the HTML file
name = sys.argv[1].split(".")
file_html = name[0]+".html"

f_html = open(file_html,"w")

f_html.write('<title>Resultado Geral</title>')
f_html.write('<html>')

f_html.write('<head>')
f_html.write('<style type="text/css">')

f_html.write('@import url(estilo.css)')

f_html.write('</style>')
f_html.write('</head>')


f_html.write ('<body>')
f_html.write ('<center>')
f_html.write ('<table align="center">')

for row in reader:
	f_html.write ('<tr align="center">')
	for column in row: 
		#For each column
		f_html.write ('<td align="center">'+ column +'</td>')
	f_html.write ('</tr>')
    
f_html.write ('</table>')
f_html.write ('</center>')
f_html.write ('</body>')
f_html.write ('</html>')

